package cn.shengchao.wecom.wxcp.acl.adapters.repositories;

import cn.shengchao.wecom.utils.JsonUtils;
import cn.shengchao.wecom.wxcp.acl.ports.repositories.ICpCallbackMsgRepository;
import cn.shengchao.wecom.wxcp.infrastructure.dao.CpCallbackMsgDao;
import cn.shengchao.wecom.wxcp.infrastructure.dao.po.CpCallbackMsg;
import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: examstarapi
 * @description: 企微回调消息处理
 * @author: Xiong weiqiang
 * @create: 2025-05-09 15:29
 */
@Service
public class CpCallbackMsgRepository implements ICpCallbackMsgRepository {
    @Autowired
    private CpCallbackMsgDao cpCallbackMsgDao;
    @Override
    public void save(WxCpXmlMessage wxMessage) {
        String wxMessageType = wxMessage.getMsgType();
        String event = wxMessage.getEvent();
        String changeType=wxMessage.getChangeType();
        Long createTime = wxMessage.getCreateTime();
        String content = JsonUtils.toJson(wxMessage);
        CpCallbackMsg cpCallbackMsg = CpCallbackMsg.builder()
                .msgType(wxMessageType)
                .event(event)
                .changeType(changeType)
                .msgCreateTime(createTime)
                .msgContentJson(content)
                .msgStatus(0).build();
        cpCallbackMsgDao.insert(cpCallbackMsg);
    }
}